//var myUser = prompt('请输入用户名');
var myUser = '于凤翔';

var ws = new WebSocket("ws://localhost:8181");

//建立连接时 触发的事件
ws.onopen = function (e) {
    console.log('Connection to server opened');
}

//连接关闭时 触发的事件
ws.onclose = function(e){
    console.log("close");
}


//发送数据到服务器
function sendMessage(user,obj){
    //像服务器发送消息
    ws.send(JSON.stringify({
        user:user,
        msg:obj
    }));
}

//接收服务器返回的数据
ws.onmessage = function(e){
    console.log(e.data);
}

//抢地主
function qiangdizhu(){
    sendMessage(myUser,{
        func:'QDZ'
    })
}

function chupai(pais){
    sendMessage(myUser,{
        func:"CP",
        cont:pais
    });
}